/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package ruptela;
/**
 *
 * @author Bartlomiej Zeslawski, Globtrak Polska Sp. z o. o.
 */
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CardTerminals;
import javax.smartcardio.TerminalFactory;
import ruptela.TerminalCard;

public class Reader {
    private ArrayList<TerminalCard> terminals;
    
    public Reader() {
        terminals = new ArrayList<TerminalCard>();
    }

    public List getList() {
        for (TerminalCard tc : terminals) {
            tc.disconnect();
        }
        TerminalFactory terminalFactory = TerminalFactory.getDefault();
        terminals = new ArrayList();
        try {
            for (CardTerminal cardTerminal : terminalFactory.terminals().list()) {
                if (!cardTerminal.isCardPresent()) continue;
                try {
                    terminals.add(new TerminalCard(cardTerminal));
                }
                catch (CardException ex) {
                    System.out.println(ex);
                }
            }
        }
        catch (CardException ex2) {
            System.out.println(ex2);
        }
        return terminals;
    }
}

